package com.ruoyi.plus.api;

import com.ruoyi.common.core.api.ApiResult;
import com.ruoyi.common.core.api.BaseApi;
import com.ruoyi.common.core.api.version.ApiVersion;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanCopyUtil;
import com.ruoyi.plus.api.vo.SysDictDataVo;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Api(tags = "dictApi-字典Api")
@ApiVersion
@RestController
@RequestMapping(value = {"/app/api/plus/sysDictApi"})
public class SysDictApi extends BaseApi {

    @Autowired
    private ISysDictDataService dictDataService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 根据字典类型查询字典数据信息
     */
    @ApiOperation("listDataByType-根据字典类型查询字典数据信息")
    @GetMapping(value = "/listDataByType/{dictType}")
    @ResponseBody
    public ApiResult<List<SysDictDataVo>> dictType(@PathVariable String dictType) {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data)) {
            data = new ArrayList<>();
        }
        List<SysDictDataVo> dictDataVos = BeanCopyUtil.copyListProperties(data, SysDictDataVo::new);
        return new ApiResult<List<SysDictDataVo>>().setData(dictDataVos);
    }
}
